package com.doone.telmarket.infrastructure.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.doone.telmarket.domain.Service;
import com.doone.telmarket.infrastructure.dao.BaseDaoSupport;
import com.doone.telmarket.infrastructure.dao.ServiceDAO;
import com.doone.telmarket.infrastructure.dao.ServiceKeepDAO;
import com.doone.telmarket.infrastructure.dao.ServicePageContentDao;
import com.doone.telmarket.infrastructure.dao.ServicePageDAO;
import com.doone.telmarket.infrastructure.dao.ServiceProductDAO;

/**
 * 
 * @author 吴同庆
 * @date 2009-9-15
 * @description 增值业务实体数据访问接口实现类
 * @package     com.doone.telmarket.infrastructure.dao.impl
 */
@Repository("serviceDAO")
public class ServiceDAOImpl extends BaseDaoSupport implements ServiceDAO {

	@Autowired
	private ServicePageDAO servicePageDao;
	
	@Autowired
	private ServiceProductDAO serviceProductDao;
	@Autowired
	private ServicePageContentDao servicePageContentDao;
	@Autowired
	private ServiceKeepDAO serviceKeepDao;
	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 根据ID获取增值业务
	 * @date 2009-9-23
	 */
	public Service selectServiceByPrimaryKey(Integer serviceCode) {
		Service service = (Service) getSqlMapClientTemplate().queryForObject("Service.selectByPrimaryKey", serviceCode);
		return service;
	}

	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 保存增值业务
	 * @date 2009-9-23
	 */
	public Service insertService(Service service) {
		getSqlMapClientTemplate().insert("Service.insertService", service);
		return service;
	}

	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 根据增值业务类型获取增值业务
	 * @date 2009-9-23
	 */
	@SuppressWarnings("unchecked")
	public List<Service> getServiceList(Service service) {

		return getSqlMapClientTemplate().queryForList("Service.serlectServiceByType", service);
	}

	/**
	 * @package com.doone.telmarket.domain.ibator
	 * @author 甘雨波
	 * @description 根据ID删除增值业务
	 * @date 2009-9-23
	 */
	public int deleteServiceById(Integer id) {
		servicePageDao.deleteServicePageByServiceCode(id);
		serviceProductDao.deleteServiceProductByServiceCode(id);
		servicePageContentDao.deleteByServicePageCode(id);
		serviceKeepDao.deleteByServiceCode(id);
		serviceProductDao.deleteIndexHotByServiceCode(id);
		return getSqlMapClientTemplate().delete("Service.ibatorgenerated_deleteByPrimaryKey", id);
	}

	@SuppressWarnings("unchecked")
	public List<Service> getAllService() {
		return getSqlMapClientTemplate().queryForList("Service.selectAllService");
	}

}
